You do sort of create a temp struct, but it doesn't work like an array, it works like :
Code:
#include <stdio.h>
#include <stdlib.h>
struct addressBook {
char * name;
int number;
struct addressBook *next;
struct addressBook *prev;
};
void link(struct addressBook *linked,struct addressBook *next, struct addressBook *prev);
int main(void)
{
struct addressBook *addEntry0,*addEntry1, *addEntry2;
struct addressBook *temp;
addEntry0 = (struct addressBook *) malloc(sizeof(struct addressBook));
addEntry1 = (struct addressBook *) malloc(sizeof(struct addressBook));
addEntry2 = (struct addressBook *) malloc(sizeof(struct addressBook));
addEntry0->number = 12434;
addEntry0->name = "Ben";
addEntry0->prev = NULL;
addEntry1->number = 12344;
addEntry1->name = "Sophia";
addEntry2->number = 3333;
addEntry2->name = "Jim";
addEntry2->next = NULL;
link(addEntry1, addEntry2, addEntry0);
printf("----Forward----\n");
for(temp = addEntry0; temp != NULL; temp = temp->next)
printf("Name: %s\n #%d\n\n", temp->name, temp->number);
printf("----Backward----\n");
for(temp = addEntry2; temp != NULL; temp = temp->prev)
printf("Name: %s\n #%d\n\n", temp->name, temp->number);
return 0;
}
void link(struct addressBook *linked,struct addressBook *next, struct addressBook *prev)
{
linked->prev = prev; ///mid prev is first
linked->next = next; ///mid next is last
prev->next = linked; ///first next is mid
next->prev = linked; ///last prev is mid
}
Where temp is a struct pointer used to walk down the list of addresses. Also I added a linker, so took the struct out of the main function. It's not necessary to make a link function though.